<?php
/* @var $this CourseController */
/* @var $model Course */
/* @var $id course id */
$this->main_menu = MenuHelper::getArrayForMainMenu(false, true, false);
?>

<?php
$this->widget('bootstrap.widgets.TbTabs', array(
	'type'=>'tabs', // 'tabs' or 'pills'
	'tabs'=>array(
		array('label'=>'Übersicht', 'url'=>$this->createUrl('course/admin'), 'active'=>false),
		array('label'=>'NEU', 'url'=>$this->createUrl('course/create'), 'active'=>false),
		array('label'=>'NEU aus Vorlage', 'url'=>$this->createUrl('course/chooseTemplate'), 'active'=>false),
        array('label'=>'Stammdaten', 'url'=>$this->createUrl('course/update', array('id'=>$id)), 'active'=>false),
        array('label'=>'Kombi', 'url'=>$this->createUrl('course/viewSubModules', array('id'=>$id)), 'active'=>true),
        array('label'=>'Trainer', 'url'=>$this->createUrl('course/trainer', array('id'=>$id)), 'active'=>false),
        array('label'=>'Teilnehmer', 'url'=>$this->createUrl('course/user', array('id'=>$id)), 'active'=>false),	),
));
?>

<h3><br>Zugebuchte Module:</h3>

<?php
    $course = Course::model()->findByPk($id);    
    $modules = new CArrayDataProvider($course->children, array(
       'keyField' => 'course_id', 
    ));
?>

<?php
//var_dump($model->subModules);
    $this->widget('bootstrap.widgets.TbExtendedGridView', array(
//    'filter'=>$modules,
    'fixedHeader' => false,
    'headerOffset' => 40, 
    'type'=>'striped bordered',
    'dataProvider' => $modules,
    'template' => "{items}",
	'columns'=>array(
            array(
                'name'=>'Kurs-Nr',
                'value'=>'$data->course_nr',
            ),
            array(
                'name'=>'Titel',
                'value'=>'$data->title',
            ),
            array (
                'class'=>'CButtonColumn',
                'template'=>'{entfernen}',
                'buttons' => array(
                  'entfernen' => array(
                    'url'=>'Yii::app()->createUrl("course/deleteSubModuleFromCourse", array("module_id"=>$data->course_id, "course_id"=>' . $id . '))',  
                  ),
                ),
            ),
	),
    ));
?>


<h3><br>Module hinzufügen:</h3>

<div class="search-form" style="display:block">

<?php /*
$this->renderPartial('_sub_module_search',array(
	'model'=>$model,
    'id'=>$id,
)); 
*/?>



<?php
	$course = Course::model()->findByPk($id);
	$criteria = new CDbCriteria;
	
	// change date format for query
	$originalStartDate = $course->start;
	$startDateFormat = date("Y-m-d", strtotime($originalStartDate));
	
	$originalEndDate = $course->end;
	$endDateFormat = date("Y-m-d", strtotime($originalEndDate));
	
	$criteria->condition='start>=:course_start AND end<=:course_end AND is_module=:is_module';
	$criteria->params=array(':course_start'=>$startDateFormat, ':course_end'=>$endDateFormat, ':is_module'=>1);
	
	$modules = Course::model()->findAll($criteria); 
	
	
	$dataProvider=new CActiveDataProvider('Course', array(
	    'criteria'=>array(
	        'condition'=>'start>=:course_start AND end<=:course_end AND is_module=:is_module',
	        'params'=>array(
				':course_start'=>$startDateFormat, ':course_end'=>$endDateFormat, ':is_module'=>1
			),
	    ),
	));
?>

<?php $form=$this->beginWidget('CActiveForm', array(
    'enableAjaxValidation'=>true,
)); ?>
 
<?php 
    $this->widget('bootstrap.widgets.TbExtendedGridView', array(
//    'filter'=>$modules,
    'fixedHeader' => false,
    'headerOffset' => 40, 
    'type'=>'striped bordered',
    'dataProvider' => $dataProvider,
    'template' => "{items}",
    'columns'=>array(
        array(
            'id'=>'autoId',
            'class'=>'CCheckBoxColumn',
            'selectableRows' => '50',   
        ),
        'course_nr',
        'title',
        'start',
        'end',
    ),
)); ?>

<?php echo CHtml::button('Zubuchen', array('submit' => array('course/addSubmoduleToCourse',
                                         'id'=>$id))); ?>
<?php $this->endWidget(); ?>
</div>
